<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    dialog-width="650px"
    :page-show="pageShow"
    @dialog-close="dialogClose"
  >
    <template #toolPanel >
      <el-dialog title="批量编辑分销商产品" size="small" width="800px" :visible.sync="batchFormVisible" :close-on-click-modal="false">
        <el-form :model="batchForm" label-width="100px" :inline="true" ref="batchForm">
          <el-form-item label="运营商:" prop="operatoruid">
            <el-select v-model="batchForm.operatoruid" filterable  :disabled="true" @change="changeOperator" placeholder="请选择运营商">
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>

          </el-form-item>

          <el-form-item label="省份:" prop="provinceuuid">
            <el-select v-model="batchForm.provinceuuid"  filterable :disabled="true" @change="selectCity(batchForm.provinceuuid)"  placeholder="请选择省份">
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="地市:"  >
            <el-select v-model="batchForm.cityName" filterable :disabled="true" clearable placeholder="请选择地市">
              <el-option
                v-for="item in citys"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型:" prop="busuuid">
            <el-select v-model="batchForm.busuuid" filterable :disabled="true" placeholder="请选择业务类型">
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="分销商:" >
            <el-select v-model="batchForm.useruuid"   :disabled="true" multiple collapse-tags clearable placeholder="请选分销商">
              <el-option
                v-for="item in users"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="折扣:"  prop="unitPrice">
            <el-input v-model="batchForm.unitPrice" style="width: 198px;" v-on:input="discountBatchChangeAdd"></el-input>
          </el-form-item>
          <el-form-item label="权益包型:" prop="channe">
            <el-checkbox-group v-model="batchForm.channe" @change="handleBatchCheckedChange">
              <el-checkbox v-for="channel in channels" :disabled="true" :label="channel.basePrice" :key="channel.baseId">{{channel.baseName}}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>

          <el-table :data="setBatchProducts"  show-overflow-tooltip="true"   max-height="620" border style="width: 100%;">
            <el-table-column type="index" width="80" label="编号">
            </el-table-column>
            <!-- <el-table-column prop="productCode" label="虚拟编码" show-overflow-tooltip width="130px"> -->
            <!-- </el-table-column> -->
            <el-table-column prop="productName" label="产品名称" show-overflow-tooltip width="130px">
            </el-table-column>
            <el-table-column prop="downfacevalue" width="100px" label="面值" :formatter="downfacevalueProduct" >
            </el-table-column>
            <el-table-column prop="price" width="110px" label="原价" :formatter="downfacevalueprice">
            </el-table-column>
            <el-table-column prop="discount" width="100px" show-overflow-tooltip label="实际折扣">
            </el-table-column>
            <el-table-column prop="discountAmount" show-overflow-tooltip label="实际金额">
            </el-table-column>

          </el-table>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button size="small" round @click.native="batchFormVisible = false">取消</el-button>
          <el-button size="small" round type="primary" @click.native="batchEditDownProduct">提交</el-button>
        </div>
      </el-dialog>

      <el-dialog title="批量编辑分销商产品" size="small"  width="700px" :visible.sync="batchFormVisibleAll" :close-on-click-modal="false">
        <el-form :model="batchForm" label-width="100px" :inline="true" ref="batchForm">
          <el-form-item label="运营商:" prop="operatoruid">
            <el-select v-model="batchForm.operatoruid" filterable :disabled="true" @change="changeOperator" placeholder="请选择运营商">
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>

          </el-form-item>

          <el-form-item label="省份:" prop="provinceuuid">
            <el-select v-model="batchForm.provinceuuid" filterable :disabled="true" @change="selectCity(batchForm.provinceuuid)"  placeholder="请选择省份">
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="地市:"  >
            <el-select v-model="batchForm.cityName" filterable  :disabled="true" clearable placeholder="请选择地市">
              <el-option
                v-for="item in citys"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型:" prop="busuuid">
            <el-select v-model="batchForm.busuuid" filterable  :disabled="true" placeholder="请选择业务类型">
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="分销商:" >
            <el-select v-model="batchForm.useruuid" filterable multiple collapse-tags :disabled="true" placeholder="请选分销商">
              <el-option
                v-for="item in users"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="折扣:"  prop="unitPrice">
            <el-input v-model="batchForm.unitPrice" style="width: 198px;" v-on:input="discountBatchChangeAddAll"></el-input>
          </el-form-item>
          <el-table :data="setBatchProductsAll"  show-overflow-tooltip="true" max-height="620" border style="width: 100%;">
            <el-table-column type="index" width="80" label="编号">
            </el-table-column>
            <!--                    <el-table-column prop="productCode" label="虚拟编码" show-overflow-tooltip width="130px">-->
            <!--                    </el-table-column>-->
            <el-table-column prop="productName" label="产品名称" show-overflow-tooltip width="130px">
            </el-table-column>
            <el-table-column prop="downfacevalue"  width="100px" label="面值" :formatter="downfacevalueProduct" >
            </el-table-column>
            <el-table-column prop="price"  width="110px" label="原价"   :formatter="downfacevalueprice">
            </el-table-column>
            <el-table-column prop="discount"  width="100px" show-overflow-tooltip label="实际折扣">
            </el-table-column>
            <el-table-column prop="discountAmount" show-overflow-tooltip label="实际金额">
            </el-table-column>

          </el-table>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button size="small" round @click.native="batchFormVisibleAll = false">取消</el-button>
          <el-button size="small" round type="primary" @click.native="batchEditDownProductAll">提交</el-button>
        </div>
      </el-dialog>

      <el-dialog title="产品匹配策略" size="big" width="1000px" :visible.sync="matchVisible" :close-on-click-modal="false">
        <el-form :model="matchForm" :inline="true" label-width="100px" ref="matchForm">
          <el-form-item label="运营商" prop="operatoruid">
            <el-select v-model="matchForm.operatoruid" filterable clearable placeholder="请选择运营商">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省份" prop="provinceuuid">
            <el-select v-model="matchForm.provinceuuid"  filterable @change="selectCity(matchForm.provinceuuid)" clearable placeholder="请选择省份">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="地市"  >
            <el-select v-model="matchForm.cityName" clearable filterable placeholder="请选择地市">
              <el-option
                v-for="item in citys"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型" prop="busuuid">
            <el-select v-model="matchForm.busuuid" clearable filterable placeholder="请选择业务类型">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="供货商" prop="useruuid">
            <el-select v-model="matchForm.useruuid" clearable filterable @change="changeBatchUser" placeholder="请选择供货商">
              <el-option
                v-for="item in usersUp"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="面值">
            <!--                    <el-input style="width:220px;" clearable v-model="" clearable placeholder="面值"></el-input>-->
            <el-select v-model="matchForm.upfacevalue" clearable filterable collapse-tags multiple placeholder="请面值">
              <el-option
                v-for="item in downfacevalues"
                :key="item.id"
                :label="item.id"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="small" round v-on:click="downProductMatchFind">查询</el-button>
          </el-form-item>
          <el-row style="color: red;margin-bottom: 10px;">
            <span>选择需要手动匹配的供货商,手动匹配后该分销商产品将直接匹配该供货商产品进行业务充值</span>
          </el-row>
          <!--列表-->
          <el-table :data="upproducts" highlight-current-row border @select="selectTable" max-height="620" header-align="center" align="center" ref="multipleTable" show-overflow-tooltip="true"
                    @selection-change="handleSelectionChangeBatch" style="width: 100%;">
            <el-table-column type="selection" width="39"  >
            </el-table-column>
            <el-table-column prop="operators.operatorname"  width="80px"  label="运营商">
            </el-table-column>
            <el-table-column prop="provincialInformation.provincename" width="50px" align="center"  label="省份">
            </el-table-column>
            <el-table-column prop="businessType.busname"  width="80px" label="业务类型">
            </el-table-column>
            <el-table-column prop="user.username" width="100px" label="供货商">
            </el-table-column>
            <el-table-column prop="productCode" show-overflow-tooltip  width="80px" label="产品编码">
            </el-table-column>
            <el-table-column prop="productName" show-overflow-tooltip  width="120px" label="产品名称">
            </el-table-column>
            <el-table-column prop="price"  width="90px" label="原价">
            </el-table-column>
            <el-table-column prop="upfacevalue" label="面值"  width="80px" :formatter="productUp">
            </el-table-column>
            <el-table-column prop="discount" width="80px" label="实际折扣">
            </el-table-column>
            <el-table-column prop="discountAmount"   width="90px" label="实际金额" show-overflow-tooltip>
            </el-table-column>
            <!--<el-table-column prop="fastchargetype" label="快慢类型":formatter="fastchargetype" >-->
            <!--</el-table-column>-->
            <el-table-column prop="status" label="状态" :formatter="status">
            </el-table-column>
          </el-table>

          <!--工具条-->
          <el-pagination
            @current-change="handleCurrentChangeMatch"
            @size-change="handleSizeChangeMatch"
            layout="total,sizes,prev, pager, next"
            :total="totalMatch">
          </el-pagination>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button size="small" round @click.native="matchVisible = false">取消</el-button>
          <el-button size="small" round type="primary" @click.native="saveMatch">保存策略</el-button>
        </div>
      </el-dialog>

      <el-dialog title="定时调价" size="big" width="1200px" :visible.sync="matchFormBatchLoading" :close-on-click-modal="false">
        <el-form :model="matchBatchForm" :inline="true" label-width="100px" ref="matchBatchForm">
          <el-form-item label="运营商" prop="operatoruid">
            <el-select v-model="matchBatchForm.operatoruid" placeholder="请选择运营商">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省份" prop="provinceuuid">
            <el-select v-model="matchBatchForm.provinceuuid" @change="selectCity(matchBatchForm.provinceuuid)" placeholder="请选择省份">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="地市"  >
            <el-select v-model="matchBatchForm.cityName"  clearable placeholder="请选择地市">
              <el-option
                v-for="item in citysMatchs"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型" prop="busuuid">
            <el-select v-model="matchBatchForm.busuuid" placeholder="请选择业务类型">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="分销商" prop="useruuid">
            <el-select v-model="matchBatchForm.useruuid"   clearable filterable  multiple  placeholder="请选择分销商">
              <el-option
                v-for="item in users"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="面值">
            <el-select v-model="matchBatchForm.downfacevalue" clearable filterable  multiple placeholder="请面值">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in downfacevalues"
                :key="item.id"
                :label="item.id"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="small" round v-on:click="downProductMatchBatch">查询</el-button>
          </el-form-item>
          <el-row style="color: red;margin-bottom: 10px;">
            <el-form-item label="注意">请选择执行时间点</el-form-item>
            <el-form-item label="调价前折扣">
              <el-input v-model="matchBatchForm.beforediscount" style="width: 95px;" clearable placeholder="折扣"></el-input>
            </el-form-item>
            <el-form-item label="调价后折扣">
              <el-input v-model="matchBatchForm.afterdiscount" style="width: 95px;" v-on:input="batchTimerPriceInput" clearable placeholder="折扣"></el-input>
            </el-form-item>
            <el-form-item label="执行时间">
              <el-date-picker type="datetime" placeholder="开始时间" format="yyyy-MM-dd HH:mm:ss"   v-model="matchBatchForm.executeTime" style="width: 100%;"></el-date-picker>
            </el-form-item>
            <el-form-item label="备注">
              <el-input  type="datetime" placeholder="备注" format="yyyy-MM-dd HH:mm:ss" :maxlength="100"  v-model="matchBatchForm.note" style="width: 100%;"></el-input>
            </el-form-item>
          </el-row>
          <!--列表-->
          <el-table :data="upproductsBatch" highlight-current-row max-height="470" border
                    ref="multipleTableBatchTimer" show-overflow-tooltip="true" style="width: 100%"
                    @selection-change="handleSelectionChangeBatchTimer" >
            <el-table-column type="selection"   >
            </el-table-column>
            <el-table-column type="index" width="50" label="编号">
            </el-table-column>
            <el-table-column prop="operators.operatorname" show-overflow-tooltip width="80px" label="运营商">
            </el-table-column>
            <el-table-column prop="provincialInformation.provincename" show-overflow-tooltip width="50px" label="省份">
            </el-table-column>
            <el-table-column prop="businessType.busname"  show-overflow-tooltip width="80px" label="业务类型">
            </el-table-column>
            <el-table-column prop="user.username" width="100px" show-overflow-tooltip label="分销商">
            </el-table-column>
            <el-table-column prop="downprouuid" show-overflow-tooltip  label="产品编码">
            </el-table-column>
            <el-table-column prop="productName" show-overflow-tooltip  width="110px" label="产品名称">
            </el-table-column>
            <el-table-column prop="price"  width="100px" label="原价" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="downfacevalue" label="面值"  width="90px" show-overflow-tooltip  :formatter="productType">
            </el-table-column>
            <el-table-column prop="discount"   width="90px" show-overflow-tooltip label="实际折扣">
            </el-table-column>
            <el-table-column prop="discountAmount" width="90px" label="实际金额" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="status" label="状态" width="60px" :formatter="status">
            </el-table-column>
          </el-table>

          <!--工具条-->
          <el-pagination
            @current-change="handleCurrentChangeMatchBatchTimer"
            @size-change="handleSizeChangeMatchBatchTimer"
            layout="total,sizes,prev, pager, next"
            :page-size="pageSizeMatchBatchTimer"
            :total="totalMatchBatch">
          </el-pagination>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button size="small" round @click.native="matchFormBatchLoading = false">取消</el-button>
          <el-button type="primary" size="small" round @click.native="saveBatchPrice" >保存调价</el-button>
        </div>
      </el-dialog>

      <el-dialog title="复制产品" size="big" width="1200px" :visible.sync="copyFormBatchLoading" :close-on-click-modal="false">
        <el-form :model="copyBatchForm" :inline="true" label-width="100px" ref="copyBatchForm">
          <el-form-item label="运营商" prop="operatoruid">
            <el-select v-model="copyBatchForm.operatoruid" placeholder="请选择运营商">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省份" prop="provinceuuid">
            <el-select v-model="copyBatchForm.provinceuuid" @change="selectCity(copyBatchForm.provinceuuid)" placeholder="请选择省份">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="地市"  >
            <el-select v-model="copyBatchForm.cityName"  clearable placeholder="请选择地市">
              <el-option
                v-for="item in citysMatchs"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型" prop="busuuid">
            <el-select v-model="copyBatchForm.busuuid" placeholder="请选择业务类型">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="分销商" prop="useruuid">
            <el-select v-model="copyBatchForm.useruuid"   clearable filterable  multiple  placeholder="请选择分销商">
              <el-option
                v-for="item in users"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="面值">
            <el-select v-model="copyBatchForm.downfacevalue" clearable filterable  multiple placeholder="请面值">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in downfacevalues"
                :key="item.id"
                :label="item.id"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="复制分销商" prop="useruuid">
            <el-select v-model="copyBatchForm.touseruuid"   clearable filterable   placeholder="请选择分销商">
              <el-option
                v-for="item in users"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button size="small" round type="primary" v-on:click="copyProductMatchBatch">查询</el-button>
          </el-form-item>

          <!--列表-->
          <el-table :data="copyproductsBatch" highlight-current-row max-height="470" border
                    ref="multipleTableBatchTimer" show-overflow-tooltip="true" style="width: 100%"
                    @selection-change="handleSelectionChangeBatchCopy" >
            <el-table-column type="selection"   >
            </el-table-column>
            <el-table-column type="index" width="50" label="编号">
            </el-table-column>
            <el-table-column prop="operators.operatorname" show-overflow-tooltip width="80px" label="运营商">
            </el-table-column>
            <el-table-column prop="provincialInformation.provincename" show-overflow-tooltip width="50px" label="省份">
            </el-table-column>
            <el-table-column prop="businessType.busname"  show-overflow-tooltip width="80px" label="业务类型">
            </el-table-column>
            <el-table-column prop="user.username" width="110px" show-overflow-tooltip label="分销商">
            </el-table-column>
            <el-table-column prop="downprouuid" show-overflow-tooltip label="产品编码">
            </el-table-column>
            <el-table-column prop="productName" show-overflow-tooltip  width="110px" label="产品名称">
            </el-table-column>
            <el-table-column prop="price"  width="90px" label="原价" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="downfacevalue" label="面值"  width="90px" show-overflow-tooltip  :formatter="productType">
            </el-table-column>
            <el-table-column prop="discount"   width="90px" show-overflow-tooltip label="实际折扣">
            </el-table-column>
            <el-table-column prop="discountAmount"   width="90px" label="实际金额" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="status" label="状态" width="60px" :formatter="status">
            </el-table-column>
          </el-table>

          <!--工具条-->
          <el-pagination
            @current-change="handleCurrentChangeMatchBatchCopy"
            @size-change="handleSizeChangeMatchBatchCopy"
            layout="total,sizes,prev, pager, next"
            :page-size="pageSizeMatchBatchCopy"
            :total="totalMatchBatchCopy">
          </el-pagination>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button size="small" round @click.native="copyFormBatchLoading = false">取消</el-button>
          <el-button size="small" round type="primary" @click.native="saveBatchCopy" >保存产品</el-button>
        </div>
      </el-dialog>

      <el-dialog title="编辑分销商产品" size="small"  width="700px"  :visible.sync="editFormVisible" :close-on-click-modal="false">
        <el-form :model="editForm" label-width="100px" :inline="true" ref="editForm">
          <el-form-item label="运营商" prop="operatoruid">
            <el-select v-model="editForm.operatoruid" filterable placeholder="请选择运营商">
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省份" prop="provinceuuid">
            <el-select v-model="editForm.provinceuuid" filterable @change="selectCity(editForm.provinceuuid)" placeholder="请选择省份">
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="城市" prop="provinceuuid">
            <el-select v-model="editForm.cityName" filterable clearable placeholder="请选择地市">
              <el-option
                v-for="item in citys"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型" prop="busuuid">
            <el-select v-model="editForm.busuuid" filterable placeholder="请选择业务类型">
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="分销商" prop="useruuid">
            <el-select v-model="editForm.useruuid" filterable placeholder="请选择分销商">
              <el-option
                v-for="item in users"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="产品名称" prop="productName"  >
            <el-input style="width: 197px;" v-model="editForm.productName"></el-input>
          </el-form-item>
          <el-form-item label="原价" prop="price">
            <el-input v-model="editForm.price" style="width: 197px;" v-on:input="discountChangeEdit"></el-input>
          </el-form-item>
          <el-form-item label="面值"   prop="downfacevalue">
            <el-input width="290px" style="width: 197px;" placeholder="如10权益"  v-model="editForm.downfacevalue"></el-input>
          </el-form-item>
          <el-form-item label="折扣" prop="discount">
            <el-input v-model="editForm.discount" style="width: 197px;" v-on:input="discountChangeEdit"></el-input>
          </el-form-item>
          <!--                <el-form-item label="成本金额"  label-width="135px"  prop="discount">-->
          <!--                    <el-input v-model="editForm.discountAmount" :disabled="true"></el-input>-->
          <!--                </el-form-item>-->
          <!--                <el-form-item label="有效期" prop="validity">-->
          <!--                    <el-select v-model="editForm.validity" placeholder="请选择有效期">-->
          <!--                        <el-option value="0" label="全部">全部</el-option>-->
          <!--                        <el-option value="1" label="30天">30天</el-option>-->
          <!--                        <el-option value="2" label="当月">当月</el-option>-->
          <!--                    </el-select>-->
          <!--                </el-form-item>-->

          <el-form-item label="备注">
            <el-input width="500px;" style="width: 197px;" v-model="editForm.remark"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button size="small" round @click.native="editFormVisible = false">取消</el-button>
          <el-button size="small" round type="primary" @click.native="editSubmit" >提交</el-button>
        </div>
      </el-dialog>
    </template>

    <template #searchPanel>
      <search-panel :show-add-button="isCompetence" @insert="handleDataInsert" :show-search-button="true" @search="search"
                    :showShopBatchEdit="isCompetence" @handleShopBatchEdit="handleShopBatchEdit" :showDiscountBatch="isCompetence"
                    @discountBatch="discountBatch" @handleBatchUpProduct="handleBatchUpProduct" :showHandleBatchUpProduct="isCompetence"
                    :showHandleBatchAuto="isCompetence" @handleBatchAuto="handleBatchAuto" :showHandleBatchOpen="isCompetence"
                    @handleBatchOpen="handleBatchOpen" @handleBatchClose="handleBatchClose" :showHandleBatchClose="isCompetence"
                    @timerPrice="timerPrice" :showTimerPrice="isCompetence" :showCopyProduct="isCompetence" @copyProduct="copyProduct"
                    :showExportDataButton="isCompetence" @exportData="exportDownProduct" :left="true">
        <el-form-item label="运营商:" prop="operatoruid">
          <el-select v-model="filters.operatoruid" filterable  collapse-tags clearable placeholder="请选择运营商">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in operator"
              :key="item.operatoruid"
              :label="item.operatorname"
              :value="item.operatoruid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="省份:" prop="provinceuuid">
          <el-select v-model="filters.provinceuuid" clearable filterable collapse-tags @change="selectfilter" placeholder="请选择省份">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in info"
              :key="item.provinceuuid"
              :label="item.provincename"
              :value="item.provinceuuid">
              <span style="float: left">{{ item.provincename }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.label }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="城市:">
          <el-select v-model="filters.cityName" filterable clearable collapse-tags placeholder="请选择地市">
            <el-option
              v-for="item in infoFilters"
              :key="item.cityName"
              :label="item.cityName"
              :value="item.cityName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="业务类型:" prop="busuuid">
          <el-select v-model="filters.busuuid" filterable clearable collapse-tags placeholder="请选择业务类型">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in bus"
              :key="item.busuuid"
              :label="item.busname"
              :value="item.busuuid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分销商:"  v-show="isCompetence" prop="useruuid">
          <el-select v-model="filters.useruuid" clearable placeholder="请选择分销商" collapse-tags filterable multiple v-show="isShow"
                     @change="userChange">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in users"
              :key="item.user.useruuid"
              :label="item.user.username"
              :value="item.user.useruuid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="匹配类型:" prop="validity">
          <el-select v-model="filters.auto" filterable clearable placeholder="请选择运有效期">
            <el-option value="" label="全部">全部</el-option>
            <el-option value="0" label="自动">自动</el-option>
            <el-option value="1" label="手动">手动</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品状态:" prop="validity">
          <el-select v-model="filters.status" clearable filterable placeholder="请选择产品状态">
            <el-option value="" label="全部">全部</el-option>
            <el-option value="2" label="禁用">禁用</el-option>
            <el-option value="1" label="正常">正常</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="面值:">
          <el-select v-model="filters.downfacevalue" clearable filterable collapse-tags multiple placeholder="面值">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in downfacevalues"
              :key="item.id"
              :label="item.id"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="折扣:">
          <el-input v-model="filters.discount" clearable placeholder="折扣"></el-input>
        </el-form-item>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :current="start"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :isShowSelection="true"
        :width="275"
        @selection-change="selsChange"
      >
        <template #action="{row}">
          <el-button round size="small" v-if="isCompetence" @click="handleEdit(row)">编辑</el-button>
          <el-button round size="small" v-if="isCompetence" @click="matchStrategy(row)">匹配</el-button>
          <el-button round size="small" v-if="isCompetence" @click="handleEnable(row)"> {{row.status == 2 ? '启用' : '禁用'}}</el-button>
          <el-button round size="small" v-if="isCompetence" style="color:red;" @click="deleteEnable(row)">删除</el-button>
        </template>
      </data-table>
    </template>

    <template #dialog>
      <el-form :model="addForm" label-width="78px" inline="inline" ref="addForm">
        <el-form-item label="运营商:" prop="operatoruid">
          <el-select v-model="addForm.operatoruid" filterable @change="changeOperator" placeholder="请选择运营商">
            <el-option
              v-for="item in operator"
              :key="item.operatoruid"
              :label="item.operatorname"
              :value="item.operatoruid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="省份:" prop="provinceuuid">
          <el-select v-model="addForm.provinceuuid" filterable @change="selectCity(addForm.provinceuuid)"  placeholder="请选择省份">
            <el-option
              v-for="item in info"
              :key="item.provinceuuid"
              :label="item.provincename"
              :value="item.provinceuuid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="城市:" >
          <el-select v-model="addForm.cityName" filterable clearable placeholder="请选择地市">
            <el-option
              v-for="item in citys"
              :key="item.cityName"
              :label="item.cityName"
              :value="item.cityName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="业务类型:" prop="busuuid">
          <el-select v-model="addForm.busuuid" filterable @change="handleCheckedChange" placeholder="请选择业务类型">
            <el-option
              v-for="item in bus"
              :key="item.busuuid"
              :label="item.busname"
              :value="item.busuuid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="分销商:" prop="useruuid">
          <el-select v-model="addForm.useruuid" filterable placeholder="请选分销商">
            <el-option
              v-for="item in users"
              :key="item.user.useruuid"
              :label="item.user.username"
              :value="item.user.useruuid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="折扣:"    prop="unitPrice">
          <el-input v-model="addForm.unitPrice" style="width: 198px;" v-on:input="discountChangeAdd"></el-input>
        </el-form-item>
        <!--                <el-form-item label="流量类型" label-width="120px">-->
        <!--                    <el-radio-group v-model="addForm.packagetype">-->
        <!--                        <el-radio  :label="1">流量池</el-radio>-->
        <!--                        <el-radio  :label="0">包型</el-radio>-->
        <!--                    </el-radio-group>-->
        <!--                </el-form-item>-->
        <el-row>
          <el-form-item label="权益包型:" prop="channe">
            <el-checkbox-group v-model="addForm.channe"  style="margin-left:5px;"  @change="handleCheckedChange">
              <el-checkbox v-for="channel in channels" :label="channel.basePrice" :key="channel.baseId">{{channel.baseName}}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-row>


        <el-table :data="setProducts"  show-overflow-tooltip="true" max-height="620"  border style="width: 100%;">
          <el-table-column type="index" width="80" label="编号">
          </el-table-column>
          <!--                    <el-table-column prop="productCode" label="虚拟编码" show-overflow-tooltip width="130px">-->
          <!--                    </el-table-column>-->
          <el-table-column prop="productName" label="产品名称" show-overflow-tooltip width="130px">
          </el-table-column>
          <el-table-column prop="downfacevalue"  width="100px" label="面值" :formatter="downfacevalueProduct" >
          </el-table-column>
          <el-table-column prop="price"  width="110px" label="原价"   :formatter="downfacevalueprice">
          </el-table-column>
          <el-table-column prop="discount"  width="100px" show-overflow-tooltip label="实际折扣">
          </el-table-column>
          <el-table-column prop="discountAmount" show-overflow-tooltip  label="实际金额">
          </el-table-column>
        </el-table>

      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center;margin-top: 10px;">
        <el-button size="small" round @click.native="dialogVisible = false">取消</el-button>
        <el-button size="small" round type="primary" @click.native="addUpProduct" >提交</el-button>
      </div>
    </template>

  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
import { findPageDownProduct ,exportDownProduct,deleteDownProduct,productDownEnable,downProductMatchFind,findBatchEditDownProduct,
  batchEditDownProduct,batchEditDownProductAll,addDownBatchProduct,downProductMatchBatch,addProductStrategy,handleBatchClose,
  autoProduct,copyDownBatchProduct,batchProductTimer,updateProduct,findOneProduct,downfindlist} from '@/api/downapi'
import { findAllPro,findAllDownShopInfo,findAllBus,findOpeProBusShop,findAllUpShopInfo,findAllChannel,findByChannel,findAllCity ,findPageOperator} from '@/api/utilsapi'
import moment from "moment";
import util from "../../../utils/util";

export default {
  name: 'downProduct',
  mixins: [
    baseMixin({
      idName: 'id',
      refresh: '',
      findData: findPageDownProduct,
      format(res) {
        return res.map(data => {
          return data
        })
      }
    })
  ],
  data() {
    return {
      pageShow: true,
      dialogData:{},
      tableColumnAttributes: [
        { name: '运营商', value: 'operatorname' , formatter : this.operatornameFormatter , width:75},
        { name: '省份', value: 'provincename',formatter : this.provincenameFormatter, width:50  },
        { name: '地市', value: 'cityName' , width:50 },
        { name: '业务类型', value: 'busname' ,formatter : this.businessTypeFormatter },
        { name: '匹配策略', value: 'auto' , formatter : this.autoFormatter },
        { name: '分销商', value: 'username', formatter : this.userNameFormatter , width:110 },
        { name: '产品编码', value: 'downprouuid', width:260 },
        { name: '原价', value: 'price' },
        { name: '面值', value: 'downfacevalue' , width:50 },
        { name: '产品名称', value: 'productName' , width:120},
        { name: '实际折扣', value: 'discount' },
        { name: '实际金额', value: 'discountAmount' },
        { name: '状态', value: 'status' , formatter : this.statusFormatter  },
        { name: '已匹配', value: 'remark' },
        { name: '备注', value: 'remark' },
      ],
      filters: {
        name: '',
        cityName:'',
        downorderuuid:'',
        provinceuuid:'',
        operatoruid:'',
        busuuid: '',
        validity:'',
        useruuid: '',
        downfacevalue: [],
        auto:'',
        discount:'',
      },
      isCompetence: util.checkRoleAdminAndSuper() ? true : false,
      products: [],
      channels:[],
      setProducts:[],
      setBatchProducts:[],
      setBatchPhoneProducts:[],
      setBatchProductsAll:[],
      downfacevalues:[],
      sels:[],
      citys:[],
      //定时调价
      citysMatchs:[],
      //下拉数据
      operator: [],
      info: [],
      bus: [],
      users: [],
      usersUp:[],
      upproducts: [],
      selsBatch:[],
      selsBatchTimer:[],
      selsBatchCopy:[],
      infoFilters:[],
      matchProduct: {},
      isShow:true,
      //批量商户
      batchFormVisible: false ,
      //批量修改
      batchForm: {
        operatoruid: '',
        provinceuuid: '',
        busuuid: '',
        cityName:'',
        user: {useruuid: ''},
        productCode: '',
        downfacevalue: '',
        unitPrice: '1',
        fastchargetype: '1',
        remark: '',
        useruuid: '',
        downtimeinterva: 1,
        price:'0',
        discountAmount:'',
        channe:[],
        packagetype:1,
        downfailnum:0//重复提交次数
      },
      batchFormVisibleAll:false,
      ups:[],
      //操作类型 1单个 2批量
      enumType:1,
      totalMatch: 0,
      //新增界面数据
      form: {
        operatoruid: '',
        provinceuuid: '',
        busuuid: '',
        cityName:'',
        user: {useruuid: ''},
        productCode: '',
        downfacevalue: '',
        unitPrice: '1',
        fastchargetype: '1',
        remark: '',
        useruuid: '',
        downtimeinterva: 1,
        price:'0',
        discountAmount:'',
        channe:[],
        validity:'',
        packagetype:1,
        downfailnum:0//重复提交次数
      },
      matchForm: {
        productCode: '',
        operatoruid: '',
        provinceuuid: '',
        busuuid: '',
        useruuid: '',
        upfacevalue:[],
        cityName:'',
        downuuid:'',
        province:''
      },
      matchVisible:false,
      //新增界面数据
      addForm: {
        operatoruid: '',
        provinceuuid: '',
        busuuid: '',
        cityName:'',
        user: {useruuid: ''},
        productCode: '',
        downfacevalue: '',
        unitPrice: '1',
        fastchargetype: '1',
        remark: '',
        useruuid: '',
        downtimeinterva: 1,
        price:'0',
        discountAmount:'',
        channe:[],
        validity:'',
        packagetype:1,
        downfailnum:0//重复提交次数
      },
      startMatch: 0,
      //操作类型 1单个 2批量
      pageSizeMatch: 10,
      totalMatchBatch:0,
      startMatchBatchTimer: 0,
      pageSizeMatchBatchTimer: 100,
      matchBatchForm: {
        productCode: '',
        operatoruid: '',
        provinceuuid: '',
        busuuid: '',
        useruuid: [],
        downfacevalue:[],
        cityName:'',
        discount:0,
        beforediscount:0,
        afterdiscount:1,
        executeTime:moment().add('hour', 1).format('YYYY-MM-DD HH:mm:ss'),
        note:''
      },
      matchFormBatchLoading:false,
      copyFormBatchLoading:false,
      copyBatchForm: {
        productCode: '',
        operatoruid: '',
        provinceuuid: '',
        busuuid: '',
        useruuid: [],
        downfacevalue:[],
        downfailnum:'0',
        fastchargetype:"1",
        downtimeinterva: 1,
        cityName:'',
        discount:0,
        beforediscount:0,
        afterdiscount:1,
        executeTime:moment().add('hour', 1).format('YYYY-MM-DD HH:mm:ss'),
        note:'',
        touseruuid:''
      },
      totalMatchBatch:0,
      totalMatchBatchCopy:0,
      upproductsBatch:[],
      copyproductsBatch:[],
      startMatchBatch: 0,
      startMatchBatchCopy: 0,
      pageSizeMatchBatchCopy: 100,
      editFormVisible:false,
      //编辑界面数据
      editForm: {
        operatoruid: '',
        provinceuuid: '',
        busuuid: '',
        cityName:'',
        user: {useruuid: ''},
        productCode: '',
        downfacevalue: '',
        discount: '1',
        fastchargetype: '1',
        remark: '',
        useruuid: [],
        downtimeinterva: 1,
        productName:'',
        downprouuid: '',
        price:"0",
        discountAmount:'',
        validity:'0',
        downfailnum:0//重复提交次数
      },
      busstype :"4028b8815fcad58a015fcfc0d330001c"
    }
  },
  methods: {
    async search(form){
      let para = {
        start: 0,
        pageSize: 10,
        provinceuuid:  this.filters.provinceuuid == "0" ? "" : this.filters.provinceuuid,
        busuuid: this.filters.busuuid == "0" ? "" : this.filters.busuuid,
        downfacevalue: (this.filters.downfacevalue == "0" || this.filters.downfacevalue.length == 0)? "" : this.filters.downfacevalue  ,
        useruuid: util.checkRoleAdminAndSuper() == true ? this.filters.useruuid == "0" ? "": this.filters.useruuid.length == 0 ? "" : this.filters.useruuid : [this.$store.getters.useruuid],
        operatoruid: this.filters.operatoruid == "0" ? "": this.filters.operatoruid,
        downprouuid: '',
        fastchargetype: '',
        validity: this.filters.validity == "0" ? "": this.filters.validity,
        cityName: this.filters.cityName,
        auto: this.filters.auto,
        status: this.filters.status == "0" ? "" :this.filters.status,
        discount:this.filters.discount
      };
      this.searchOptions = para;
      this.setTableData()
    },
    selsChange: function (sels) {
      this.sels = sels;
      if(this.sels && this.sels.length > 0){
        this.matchProduct = this.sels[0];
      }
    },
    userChange: function (user) {
      this.form.useruuid = user;
    },
    exportDownProduct(){
      let para = {
        operatoruid: this.filters.operatoruid == "0" ? "" : this.filters.operatoruid ,
        provinceuuid: this.filters.provinceuuid == "0" ? "" : this.filters.provinceuuid ,
        busuuid: this.filters.busuuid == "0" ? "" : this.filters.busuuid,
        downfacevalue:  (this.filters.downfacevalue == "0" || this.filters.downfacevalue.length == 0)? "" : this.filters.downfacevalue,
        useruuid: util.checkRoleAdminAndSuper() == true ? this.filters.useruuid == "0" ? "": this.filters.useruuid : [this.$store.getters.useruuid],
        downprouuid: '',
        fastchargetype: ''
      };
      exportDownProduct(para).then((datas) => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,"error");
        } else {
          window.open(data.path);
        }
      });
    },
    handleShopBatchEdit(){
      if(this.filters.operatoruid == ""){
        this.showMsg("请先选择运营商","error");
        return;
      }
      if(this.filters.provinceuuid == ""){
        this.showMsg("请先选择省份","error");
        return;
      }
      if(this.filters.busuuid == "" && this.filters.busuuid == "4028b8815fcad58a015fcfc0d330001c"){
        this.showMsg("请先选择业务类型,并且必须不能为手机","error");
        return;
      }
      if(this.filters.useruuid == ""){
        this.showMsg("请先选择分销商","error");
        return;
      }
      this.batchForm.operatoruid = this.filters.operatoruid;
      this.batchForm.provinceuuid = this.filters.provinceuuid;
      this.batchForm.busuuid = this.filters.busuuid;
      this.batchForm.useruuid = this.filters.useruuid;
      this.changeOperator(this.filters.operatoruid);
      //查询地市
      const result = this.info.find(item => item.provinceuuid == this.batchForm.provinceuuid);
      if(result){
        this.findAllCity(result.provincename)
        this.findBatchEditDownProduct(this.filters.cityName);
      }else{
        this.findBatchEditDownProduct('');
      }
      this.batchFormVisible = true;
    },
    discountBatch(){
      if(this.filters.operatoruid == ""){
        this.showMsg("请先选择运营商",'error')
        return;
      }
      if(this.filters.provinceuuid == ""){
        this.showMsg("请先选择省份",'error')
        return;
      }
      if(this.filters.busuuid == "" ){
        this.showMsg("请先选择业务类型",'error')
        return;
      }

      if(!this.filters.discount){
        this.showMsg("请先填入批量修改折扣",'error')
        return;
      }
      this.batchForm.operatoruid = this.filters.operatoruid;
      this.batchForm.provinceuuid = this.filters.provinceuuid;
      this.batchForm.busuuid = this.filters.busuuid;
      this.batchForm.useruuid = this.filters.useruuid;
      this.changeOperator(this.filters.operatoruid);
      //查询地市
      const result = this.info.find(item => item.provinceuuid == this.batchForm.provinceuuid);
      if(result){
        this.findAllCity(result.provincename)
        this.findBatchEditDownProduct(this.filters.cityName);
      }else{
        this.findBatchEditDownProduct('');
      }
      this.batchFormVisibleAll = true;
    },
    handleBatchUpProduct(){
      this.enumType = 2;
      this.matchForm.useruuid = "";
      this.matchForm.downprouuid = "";
      if(this.filters.operatoruid == ""){
        this.showMsg("请先选择运营商",'error')
        return;
      }
      if(this.filters.provinceuuid == ""){
        this.showMsg("请先选择省份",'error')
        return;
      }
      if(this.filters.busuuid == "" ){
        this.showMsg("请先选择业务类型",'error')
        return;
      }

      if(this.filters.useruuid == ""){
        this.showMsg("请先选择分销商",'error')
        return;
      }
      if(!this.sels || this.sels.length == 0){
        this.showMsg("请先选择列表产品",'error')
        return;
      }
      this.findAllUpShopInfo();
      this.matchVisible = true;
      if(this.filters.downfacevalue){
        this.matchForm.upfacevalue = this.filters.downfacevalue
      }

      //按条件查询当前渠道产品和符合手动匹配的上游渠道产品
      this.matchForm.operatoruid = this.filters.operatoruid;
      this.matchForm.provinceuuid = this.filters.provinceuuid;
      this.matchForm.busuuid = this.filters.busuuid;
      //批量操作使用
      this.matchForm.downuuid = this.filters.useruuid;

      //查询地市
      const result = this.info.find(item => item.provinceuuid == this.matchBatchForm.provinceuuid);
      if(result){
        this.findAllCity(result.provincename)
        this.findBatchEditDownProductBatch(this.matchBatchForm.cityName,this.matchForm.upfacevalue);
      }else{
        this.findBatchEditDownProductBatch('',this.matchForm.upfacevalue);
      }
    },
    handleBatchAuto () {
      if(this.sels != null  && this.sels.length > 0){
        var temp = false;
        for(var i = 0 ; i < this.sels.length;i++){
          if(this.sels[i].auto == 0){
            this.showMsg("不能处理匹配模式为自动的产品","error");
            temp = true;
          }
        }
        if(!temp){
          this.$confirm('确认提交吗？', '提示', {roundButton:true}).then(() => {
            let para = {products:this.sels,auto:0};
            autoProduct(para).then(datas =>{
              let {message, code, data} = datas;
              if (code !== "0") {
                this.showMsg(message,"error");
              }else{
                this.showMsg("操作成功","success");
              }
              this.search();
            });
          });
        }
      }else{
        this.showMsg("请选择产品,并且只能处理产品为手动匹配的产品","error");
      }
    },
    handleBatchOpen(){
      if(this.sels != null  && this.sels.length > 0){
        this.$confirm('确认开启产品吗？', '提示', {roundButton:true}).then(() => {
          let para = {products:this.sels,status:1};
          handleBatchClose(para).then(datas =>{
            let {message, code, data} = datas;
            if (code !== "0") {
              this.showMsg(message,"error");
            }else{
              this.showMsg("操作成功","success");
            }
            this.search();
          });
        });
      }else{
        this.showMsg("请选择产品","error");
      }
    },
    handleBatchClose(){
      if(this.sels != null  && this.sels.length > 0){
        this.$confirm('确认关闭产品吗？', '提示', {roundButton:true}).then(() => {
          let para = {products:this.sels,status:2};
          handleBatchClose(para).then(datas =>{
            let {message, code, data} = datas;
            if (code !== "0") {
              this.showMsg(message,"error");
            }else{
              this.showMsg("操作成功","success");
            }
            this.search();
          });
        });
      }else{
        this.showMsg("请选择产品","error");
      }
    },
    timerPrice(){
      if(this.filters.operatoruid == ""){
        this.showMsg("请先选择运营商","error");
        return;
      }
      if(this.filters.provinceuuid == ""){
        this.showMsg("请先选择省份","error");
        return;
      }

      if(this.filters.busuuid == ""){
        this.showMsg("请先选择业务类型","error");
        return;
      }

      if(this.filters.useruuid == ""){
        this.showMsg("请先选择分销商","error");
        return;
      }
      this.matchBatchForm.operatoruid = this.filters.operatoruid;
      this.matchBatchForm.provinceuuid = this.filters.provinceuuid;
      this.matchBatchForm.busuuid = this.filters.busuuid;
      this.matchBatchForm.useruuid = this.filters.useruuid;
      this.matchBatchForm.downfacevalue = this.filters.downfacevalue;
      this.matchFormBatchLoading = true;
      this.downProductMatchBatch();
    },
    copyProduct(){
      if(this.filters.operatoruid == ""){
        this.showMsg("请先选择运营商","error")
        return;
      }
      if(this.filters.provinceuuid == ""){
        this.showMsg("请先选择省份","error")
        return;
      }

      if(this.filters.busuuid == ""){
        this.showMsg("请先选择业务类型","error")
        return;
      }

      if(this.filters.useruuid == ""){
        this.showMsg("请先选择分销商","error")
        return;
      }
      this.copyBatchForm.operatoruid = this.filters.operatoruid;
      this.copyBatchForm.provinceuuid = this.filters.provinceuuid;
      this.copyBatchForm.busuuid = this.filters.busuuid;
      this.copyBatchForm.useruuid = this.filters.useruuid;
      this.copyBatchForm.downfacevalue = this.filters.downfacevalue;
      this.copyFormBatchLoading = true;
      this.copyProductMatchBatch();
    },
    selectfilter(row){
      this.filters.cityName = '';
      if(row != ""){
        const result = this.info.find( item => {return item.provinceuuid == row});
        if(result){
          this.findAllCity(result.provincename);
        }
      }
    },
    async findAllCity (province,arrays) {
      let para = {
        province : province
      };
      const result = await findAllCity(para);
      this.infoFilters = [];
      this.citys = [];
      result.data.forEach((item,index) =>{
        this.citys.push({id:index,cityName:item});
        this.infoFilters.push({id:index,cityName:item});
      })
    },
    userNameFormatter(row){
      return row.user.username;
    },
    autoFormatter (row ) {
      return (row.auto === 1) ? "手动匹配" : (row.auto === 0) ?  "自动匹配" : "未知";
    },
    operatornameFormatter (row ) {
      return row.operators.operatorname;
    },
    businessTypeFormatter(row){
      return row.businessType.busname;
    },
    productType: function (row, column) {
      return (row.businessType.busname == "手机") ? (row.downfacevalue + '权益') : ( row.businessType.busname == "固话") ?  (row.downfacevalue + '权益') :(row.downfacevalue + '元');
    },
    statusFormatter (row, column) {
      return row.status == "1" ? '正常' : row.status == "0" ? '删除' : row.status == "2" ? "禁用" : '未知';
    },
    provincenameFormatter(row){
      return row.provincialInformation.provincename;
    },
    deleteEnable(row){
      this.$confirm('确定删除产品吗?', '提示', {
        type: 'warning',
        roundButton:true
      }).then(() => {
        deleteDownProduct([row]).then(datas => {
          this.resultSuccess(datas);
        });
      }).catch(() => {
      });
    },
    handleEnable (row) {
      this.$confirm('确认更新该产品状态吗?', '提示', {
        type: 'warning',
        roundButton:true
      }).then(() => {
        let para = {
          downprouuid: row.downprouuid,
          status: row.status == "2" ? "1" : "2",
          useruuid: this.$store.getters.useruuid
        };
        productDownEnable(para).then((res) => {
         this.resultSuccess(res);
        });
      }).catch(() => {

      });
    },
    matchStrategy(row) {
      this.enumType = 1;
      this.matchForm.useruuid = "";
      this.matchForm.downuuid = "";
      this.matchProduct = row;
      this.matchVisible = true;
      const oper =  this.operator.find(item => {return row.operators.operatorname == item.operatorname});
      if(oper){
        this.matchForm.operatoruid = oper.operatoruid;
      }
      const infoCity =  this.info.find(item => {return row.provincialInformation.provincename == item.provincename});
      if(infoCity){
        this.matchForm.provinceuuid = infoCity.provinceuuid;
      }
      const busInfo =  this.bus.find(item => {return row.businessType.busname == item.busname});
      if(busInfo){
        this.matchForm.busuuid = busInfo.busuuid;
      }

      const downUser = this.users.find(item => {return item.username == row.user.username});
      if(downUser){
        this.matchForm.downuuid = downUser.user.useruuid;
      }

      this.matchForm.upfacevalue = [row.downfacevalue];
      this.downProductMatchFind(row);
    },
    async findOpeProBusShop(){
      let para = {test: ''};
      const result = await findOpeProBusShop(para);
      if(result.code == "0"){
        this.info = result.data.info;
        this.bus = result.data.bus;
        this.operator = result.data.operator;
      }
    },
    // async findPageOperator(){
    //   let para = {
    //     start: 1,
    //     pageSize:101,
    //     operatorname:'',
    //   };
    //   findPageOperator(para).then((datas) => {
    //     let { message, code, data } = datas;
    //     if (code !== "0") {
    //       this.showMsg(message,'error')
    //     } else if(data && data.result){
    //       this.operator = data.result;
    //     }
    //   });
    // },
    async findAllChannel(){
      let para = {
        province : ""
      };
      const result = await findAllChannel(para);
      if(result && result.data){
        result.data.forEach(item =>{
          this.downfacevalues.push({id:item,value:item});
        });
      }
    },
    async findAllDownShopInfo(){
      let para = {useruuid: this.$store.getters.useruuid};
      const result = await findAllDownShopInfo(para);
      if(result.data){
        this.users = result.data;
      }
    },
    findBatchEditDownProduct(cityName){
      this.setBatchProducts = [];
      this.setBatchPhoneProducts = [];
      this.batchForm.channe = [];
      this.setBatchProductsAll = [];
      let  para = {
        operatoruid : this.filters.operatoruid,
        provinceuuid : this.filters.provinceuuid,
        busuuid : this.filters.busuuid,
        useruuid : this.filters.useruuid,
        cityName: cityName,
        discount:this.filters.discount,
        downfacevalue :  (this.filters.downfacevalue == "0" || this.filters.downfacevalue.length == 0)? "" : this.filters.downfacevalue
      }
      findBatchEditDownProduct(para).then(results =>{
        let {message, code, data} = results;
        if (code !== "0") {
          this.showMsg(message,'error')
        }
        if(!data || data.length == 0){
          this.showMsg("没有找到产品,请重新选择",'error')
        }else{
          for(var pro in data){
            this.batchForm.channe.push(parseInt(data[pro].downfacevalue));
            var obj = new Object();
            obj.price = data[pro].price;
            obj.downfacevalue = data[pro].downfacevalue;
            obj.discount = data[pro].discount;
            obj.discountAmount = data[pro].discountAmount;
            obj.downprouuid = data[pro].downprouuid;
            obj.productName = data[pro].productName;
            obj.productCode = data[pro].productCode;
            this.batchForm.unitPrice = data[pro].discount+'';
            if(cityName){
              this.batchForm.cityName = data[pro].cityName;
            }
            this.setBatchProducts.push(obj);
            this.setBatchPhoneProducts.push(obj);
            this.setBatchProductsAll.push(obj);
          }
        }
      });
    },
    batchEditDownProduct() {
      this.$confirm('确认提交吗？', '提示', {roundButton: true}).then(() => {
        let para = Object.assign({}, this.batchForm);
        para.products = this.setBatchProducts;
        batchEditDownProduct(para).then((datas) => {
          this.resultSuccess(datas);
          this.batchFormVisible = false;
        });
      });
    },
    changeOperator(value){
      this.addForm.channe = [];
      let para = {
        operatoruid:value
      };
      findByChannel(para).then(datas =>{
        let {message, code, data} = datas;
        if (code !== "0") {
          this.$message({
            message: message,
            type: 'error'
          });
        } else {
          this.channels = data;
        }
      })
    },
    downfacevalueprice(row){
        return this.addForm.busuuid == undefined ? row.price :  this.addForm.busuuid == this.busstype? row.price+"元" : row.price+"元";
    },
    downfacevalueProduct (row) {
      return this.addForm.busuuid == undefined ? row.downfacevalue :  this.addForm.busuuid == this.busstype? row.downfacevalue+"元" : row.downfacevalue+"元";
    },
    handleBatchCheckedChange(){
      this.batchProduct();
    },
    batchProduct(){
      this.setBatchProducts.forEach(item =>{
        item.discount = (item.price * this.batchForm.unitPrice / item.price).toFixed(5);
        item.discountAmount = (item.price * this.batchForm.unitPrice ).toFixed(5);
      })
    },
    discountBatchChangeAdd(){
      this.batchProduct();
    },
    selectCity(provinceuuid){
      const result = this.info.find(item => item.provinceuuid == provinceuuid);
      if(result){
        this.findAllCity(result.provincename)
      }
      if(provinceuuid ){
        if(this.setBatchProducts){
          const result = this.info.find(item => { return item.provinceuuid ==  provinceuuid});
          if(result){
            this.setBatchProducts.forEach( item =>{
              const face = item.productName.replace(/[^0-9]/ig,"");
              item.productName = result.provincename + face + "权益";
            });
          }
        }
        if(this.setProducts){
          const result = this.info.find(item => { return item.provinceuuid ==  provinceuuid});
          if(result){
            this.setProducts.forEach( item =>{
              const face = item.productName.replace(/[^0-9]/ig,"");
              item.productName = result.provincename + face + "权益";
            });
          }
        }
      }
    },
    discountBatchChangeAddAll(){
      this.batchProductAll();
    },
    batchProductAll(){
      this.setBatchProductsAll.forEach(obj =>{
        obj.discount = (obj.price * this.batchForm.unitPrice / obj.price).toFixed(5);
        obj.discountAmount = (obj.price * this.batchForm.unitPrice ).toFixed(5);
      });
    },
    batchEditDownProductAll(){
      this.$confirm('确认提交吗？', '提示', {roundButton:true}).then(() => {
        let para = Object.assign({}, this.batchForm);
        para.products = this.setBatchProductsAll;
        batchEditDownProductAll(para).then((datas) => {
          this.resultSuccess(datas);
          this.batchFormVisibleAll = false;
        });
      });
    },
    handleCheckedChange(){
      this.gernProduct();
    },
    gernProduct(){
      var temps = this.setProducts;
      this.setProducts = [];
      for(var cha in this.addForm.channe){
        for(var ch in this.channels){
          if(this.channels[ch].basePrice +""== this.addForm.channe[cha]){
            if(this.addForm.packagetype == 1){
              var obj = new Object();
              obj.price = this.channels[ch].basePrice;
              obj.downfacevalue = this.channels[ch].flow;
              obj.discount = (this.channels[ch].basePrice * this.addForm.unitPrice / this.channels[ch].basePrice).toFixed(5);
              obj.discountAmount = (this.channels[ch].basePrice * this.addForm.unitPrice ).toFixed(5);
              obj.productCode = obj.downfacevalue;
              if(this.addForm.provinceuuid){
                const result = this.info.find(item => { return item.provinceuuid == this.addForm.provinceuuid });
                if(result){
                  if(this.addForm.busuuid == this.busstype){
                    obj.productName = result.provincename + obj.downfacevalue+"权益";
                  } else {
                    obj.productName = result.provincename + obj.downfacevalue+"元";
                  }
                }else{
                  if(this.addForm.busuuid == this.busstype){
                    obj.productName = obj.downfacevalue+"权益";
                  }else{
                    obj.productName = obj.downfacevalue+"元";
                  }
                }
              }else{
                if(this.addForm.busuuid == this.busstype){
                  obj.productName = obj.downfacevalue+"权益";
                }else{
                  obj.productName = obj.downfacevalue+"元";
                }
              }
              this.setProducts.push(obj);
            }else if(this.addForm.packagetype == 0){
              var obj = new Object();
              obj.price = this.channels[ch].basePrice;
              obj.downfacevalue = this.channels[ch].flow;
              obj.discount = this.addForm.unitPrice;
              obj.discountAmount = (this.channels[ch].basePrice * this.addForm.unitPrice ).toFixed(5);
              obj.productCode = obj.downfacevalue;
              if(this.addForm.provinceuuid){
                const result = this.info.find(item => { return item.provinceuuid == this.addForm.provinceuuid });
                if(result){
                  if(this.addForm.busuuid == this.busstype){
                    obj.productName = result.provincename + obj.downfacevalue+"权益";
                  }else{
                    obj.productName = result.provincename + obj.downfacevalue+"元";
                  }
                }else{
                  if(this.addForm.busuuid == this.busstype){
                    obj.productName = obj.downfacevalue+"权益";
                  }else{
                    obj.productName = obj.downfacevalue+"元";
                  }
                }
              }else{
                if(this.addForm.busuuid == this.busstype){
                  obj.productName = obj.downfacevalue+"权益";
                }else{
                  obj.productName = obj.downfacevalue+"元";
                }
              }
              this.setProducts.push(obj);
            }
          }
        }
      }
    },
    discountChangeAdd () {
      this.gernProduct();
    },
    addUpProduct () {
      this.$confirm('确认提交吗？', '提示', {roundButton:true}).then(() => {
        let para = Object.assign({}, this.addForm);
        para.products = this.setProducts;
        addDownBatchProduct(para).then((datas) => {
          this.resultSuccess(datas);
        });
      });
    },
    findBatchEditDownProductBatch(cityName,upfacevalue){
      let para = {
        start: this.startMatch,
        pageSize: this.pageSizeMatch,
        downprouuids: this.sels ? this.sels : [],
        busuuid: this.matchForm.busuuid == "0" ? "" : this.matchForm.busuuid,
        operatoruid: this.matchForm.operatoruid == "0" ? "" : this.matchForm.operatoruid,
        provinceuuid: this.matchForm.provinceuuid == "0" ? "" : this.matchForm.provinceuuid,
        useruuids: this.matchBatchForm.useruuid == "0" ? "" : this.matchBatchForm.useruuid,
        upfacevalue:upfacevalue ? upfacevalue : '',
        cityName:cityName
      };
      downProductMatchFind(para).then((datas) => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,"error");
        } else if(data) {
          this.upproducts = data.result;
          this.totalMatch = data.totalCount;
          if(!this.users){
            this.showMsg("请刷新后在试","error");
            return;
          }
          setTimeout(()=>{
            for(var j = 0 ; j < this.sels.length; j++){
              for(var i  = 0 ; i < this.upproducts.length; i++) {
                if (this.upproducts[i].remark == this.sels[j].downprouuid) {
                  this.$refs.multipleTable.toggleRowSelection(this.upproducts[i], true);
                }
              }
            }
          },1000);
        }
      });
    },
    //查询产品
    changeBatchUser(){
      this.downProductMatchBatch();
    },
    downProductMatchBatch(row){
      let para = {
        start: this.startMatchBatchTimer,
        pageSize: this.pageSizeMatchBatchTimer,
        provinceuuid:  this.matchBatchForm.provinceuuid == "0" ? "" : this.matchBatchForm.provinceuuid,
        busuuid: this.matchBatchForm.busuuid == "0" ? "" : this.matchBatchForm.busuuid,
        downfacevalue: (this.matchBatchForm.downfacevalue == "0" || this.matchBatchForm.downfacevalue.length == 0)? "" : this.matchBatchForm.downfacevalue  ,
        useruuid: (this.matchBatchForm.useruuid == "0" || this.matchBatchForm.useruuid.length == 0) ? "": this.matchBatchForm.useruuid,
        operatoruid: this.matchBatchForm.operatoruid == "0" ? "": this.matchBatchForm.operatoruid,
        downprouuid: '',
        fastchargetype: '',
        validity: "",
        cityName: this.matchBatchForm.cityName,
        auto: "",
        status: "",
        discount:this.filters.discount
      };
      findPageDownProduct(para).then((datas) => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,'error')
        } else if(data && data.result) {
          this.upproductsBatch = data.result;
          this.totalMatchBatch = data.totalCount;
          //检查所有产品折扣是否相同
          if(this.checkProductDiscount(this.upproductsBatch)){
            this.showMsg("当前选中产品折扣不相同，请注意检查",'info')
          };
        }
      });
    },
    checkProductDiscount(products){
      if(products && products.length > 0){
        const pro = products[0];
        if(!this.matchBatchForm.beforediscount){
          this.matchBatchForm.beforediscount = pro.discount;
        }
        const result = products.find(item =>{
          return item.discount != pro.discount;
        })
        if(result){
          return true;
        }
        return false;
      }
    },
    saveMatch: function () {
      if(this.matchForm.operatoruid == ""){
        this.showMsg("请先选择运营商",'error')
        return;
      }
      if(this.matchForm.provinceuuid == ""){
        this.showMsg("请先选择省份",'error')
        return;
      }
      if(this.matchForm.busuuid == ""){
        this.showMsg("请先选择业务类型",'error')
        return;
      }
      if(this.matchForm.downuuid == ""){
        this.showMsg("请先选择分销商",'error')
        return;
      }
      //如果选择了上游产品则不需要选择供货商
      if(this.matchForm.useruuid == "" && this.selsBatch.length == 0 ){
        this.showMsg("请先选择供货商",'error')
        return;
      }

      if(!this.matchProduct.downprouuid && this.sels && this.sels.length == 0){
        this.showMsg("请先选择产品",'error')
        return;
      }
      //计算批量选择
      const pros = [];
      this.sels.forEach( item => {
        pros.push(item.downprouuid);
      });
      let para = {
        downprouuid: this.enumType ==  1 ? [this.matchProduct.downprouuid ] : pros,
        downuuid: this.matchForm.downuuid,
        upuuid: this.matchForm.useruuid,
        remark:'add match',
        upprouuids:this.selsBatch,
        provinceuuid: this.matchForm.provinceuuid,
        operatoruid: this.matchForm.operatoruid,
        cityName: this.matchForm.cityName,
        busuuid: this.matchForm.busuuid
      };
      addProductStrategy(para).then(datas => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,'error')
        } else {
          this.showMsg(message,'success')
          this.matchVisible = false;
          this.search();
        }
      });
    },
    downProductMatchBatch(row){
      let para = {
        start: this.startMatchBatchTimer,
        pageSize: this.pageSizeMatchBatchTimer,
        provinceuuid:  this.matchBatchForm.provinceuuid == "0" ? "" : this.matchBatchForm.provinceuuid,
        busuuid: this.matchBatchForm.busuuid == "0" ? "" : this.matchBatchForm.busuuid,
        downfacevalue: (this.matchBatchForm.downfacevalue == "0" || this.matchBatchForm.downfacevalue.length == 0)? "" : this.matchBatchForm.downfacevalue  ,
        useruuid: (this.matchBatchForm.useruuid == "0" || this.matchBatchForm.useruuid.length == 0) ? "": this.matchBatchForm.useruuid,
        operatoruid: this.matchBatchForm.operatoruid == "0" ? "": this.matchBatchForm.operatoruid,
        downprouuid: '',
        fastchargetype: '',
        validity: "",
        cityName: this.matchBatchForm.cityName,
        auto: "",
        status: "",
        discount:this.filters.discount
      };
      findPageDownProduct(para).then((datas) => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.$message({
            message: message,
            type: 'error'
          });
        } else if(data && data.result) {
          this.upproductsBatch = data.result;
          this.totalMatchBatch = data.totalCount;
          //检查所有产品折扣是否相同
          if(this.checkProductDiscount(this.upproductsBatch)){
            this.showMsg('当前选中产品折扣不相同，请注意检查','info')
          };
        }
      });
    },
    handleCurrentChangeMatchBatchTimer: function (val) {
      this.startMatchBatchTimer = val - 1;
      this.downProductMatchBatch();
    },
    handleSizeChangeMatchBatchTimer: function (val) {
      this.pageSizeMatchBatchTimer = val;
      this.downProductMatchBatch();
    },
    handleCurrentChangeMatch: function (val) {
      this.startMatch = val - 1;
      this.downProductMatchFind();
    },
    handleSizeChangeMatch: function (val) {
      this.pageSizeMatch = val;
      this.downProductMatchFind();
    },
    downProductMatchFind: function (row) {
      let para = {
        start: this.startMatch,
        pageSize: this.pageSizeMatch,
        busuuid: this.matchForm.busuuid == "0" ? "" : this.matchForm.busuuid,
        operatoruid: this.matchForm.operatoruid == "0" ? "" : this.matchForm.operatoruid,
        provinceuuid: this.matchForm.provinceuuid == "0" ? "" : this.matchForm.provinceuuid,
        useruuids: (this.matchForm.useruuid == "0" || !this.matchForm.useruuid) ? "" : this.matchForm.useruuid,
        upfacevalue: this.matchForm.upfacevalue ? this.matchForm.upfacevalue : '',
        downprouuid : row ? row.downprouuid : ""
      };
      downProductMatchFind(para).then((datas) => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,'error')
        } else {
          this.upproducts = data.result;
          this.totalMatch = data.totalCount;
          if(!this.users){
            this.showMsg("请刷新后在试",'error')
          }
          //查询下游用户id
          if(this.matchProduct){
            const upResult = this.users.find( item => {return item.user.username == this.matchProduct.user.username});
            if(upResult && undefined != upResult && upResult.user){
              this.matchForm.downuuid = upResult.user.useruuid;
            }
            //查询上游产品id 或者名称
            setTimeout(()=>{
              for(var i  = 0 ; i < this.upproducts.length; i++) {
                if (this.upproducts[i].remark == this.matchProduct.downprouuid) {
                  this.$refs.multipleTable.toggleRowSelection(this.upproducts[i], true);
                }
              }
            },1000);
          }

        }
      });
    },
    status (row, column) {
      return row.status == "1" ? '正常' : row.status == "0" ? '删除' : row.status == "2" ? "禁用" : '未知';
    },
    productUp: function (row, column) {
      return (row.businessType.busname == "手机") ? (row.upfacevalue + '权益') : ( row.businessType.busname == "固话") ?  (row.upfacevalue + '权益') :(row.upfacevalue + '权益');
    },
    handleSelectionChange (sels) {
      this.sels = sels;
    },
    handleSelectionChangeBatch (sels) {
      this.selsBatch = sels;
    },
    selectTable (selection, row) {
      var temp = false;
      for(var i = 0 ; i < selection.lengh; i++){
        if(selection[i].upprouuid = row.upprouuid){
          temp = true;
        }
      }
      if(!temp){
      }
    },
    findAllUpShopInfo: function () {
      let para = {useruuid: ''};
      findAllUpShopInfo(para).then(datas => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,'error')
        } else {
          this.usersUp = data;
        }
      });
    },
    saveBatchCopy(){
      if(!this.copyBatchForm.touseruuid){
        this.showMsg("请选择复制到分销商","error")
        return;
      }
      this.$confirm('确定创建复制产品吗?', '提示', {
        type: 'warning',
        roundButton:true
      }).then(() => {
        let para = Object.assign({}, this.copyBatchForm);
        para.products = this.selsBatchCopy;
        copyDownBatchProduct(para).then((datas) => {
          let {message, code, data} = datas;
          if (code !== "0") {
            this.showMsg(message,"error")
            return;
          }
          this.copyFormBatchLoading = false;
          this.search()
        });
      }).catch(() => {
      });
    },
    handleSelectionChangeBatchCopy(sels){
      this.selsBatchCopy = sels;
      this.showMsg("当前已经选择"+sels.length+"个产品","info")
    },
    handleCurrentChangeMatchBatchCopy: function (val) {
      this.startMatchBatchCopy = val - 1;
      this.copyProductMatchBatch();
    },
    handleSizeChangeMatchBatchCopy: function (val) {
      this.pageSizeMatchBatchCopy = val;
      this.copyProductMatchBatch();
    },
    copyProductMatchBatch(row){
      let para = {
        start: this.startMatchBatchCopy,
        pageSize: this.pageSizeMatchBatchCopy,
        provinceuuid:  this.copyBatchForm.provinceuuid == "0" ? "" : this.copyBatchForm.provinceuuid,
        busuuid: this.copyBatchForm.busuuid == "0" ? "" : this.copyBatchForm.busuuid,
        downfacevalue: (this.copyBatchForm.downfacevalue == "0" || this.copyBatchForm.downfacevalue.length == 0)? "" : this.copyBatchForm.downfacevalue  ,
        useruuid: (this.copyBatchForm.useruuid == "0" || this.copyBatchForm.useruuid.length == 0) ? "": this.copyBatchForm.useruuid,
        operatoruid: this.copyBatchForm.operatoruid == "0" ? "": this.copyBatchForm.operatoruid,
        downprouuid: '',
        fastchargetype: '',
        validity: "",
        cityName: this.copyBatchForm.cityName,
        auto: "",
        status: "",
        discount:this.filters.discount
      };
      findPageDownProduct(para).then((datas) => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,"error")
        } else if(data && data.result) {
          this.copyproductsBatch = data.result;
          this.totalMatchBatchCopy = data.totalCount;
        }
      });
    },
    handleSelectionChangeBatchTimer(sels){
      this.selsBatchTimer = sels;
      if(sels && sels.length > 0 && !this.matchBatchForm.beforediscount ){
        this.matchBatchForm.beforediscount = sels[0].discount;
      }
      this.showMsg("当前已经选择"+sels.length+"个产品","info")
    },
    batchTimerPriceInput(){
      if(this.upproductsBatch && this.upproductsBatch.length > 0){
        this.upproductsBatch.forEach(obj =>{
          obj.discount = (obj.price * this.matchBatchForm.afterdiscount / obj.price).toFixed(5);
          obj.discountAmount = (obj.price * this.matchBatchForm.afterdiscount ).toFixed(5);
        });
      }
    },
    saveBatchPrice(){
      if(this.matchBatchForm.operatoruid == ""){
        this.showMsg("请先选择运营商","error")
        return;
      }
      if(this.matchBatchForm.provinceuuid == ""){
        this.showMsg("请先选择省份","error")
        return;
      }
      if(this.matchBatchForm.busuuid == ""){
        this.showMsg("请先选择业务类型","error")
        return;
      }
      if(this.matchBatchForm.useruuid == ""){
        this.showMsg("请先选择分销商","error")
        return;
      }
      if(this.selsBatchTimer.length == 0){
        this.showMsg("请选择产品","error")
        return;
      }
      if(!this.matchBatchForm.executeTime){
        this.showMsg("执行时间必填,请选择向前时间点执行","error")
        return;
      }

      if(this.checkProductDiscount(this.selsBatchTimer)){
        this.$confirm('产品折扣有差异，确定保存吗?', '提示', {
          type: 'warning',
          roundButton:true
        }).then(() => {
          this.saveTimer(this.matchBatchForm,this.selsBatchTimer);
        }).catch(() => {

        });
      }else{
        this.saveTimer(this.matchBatchForm,this.selsBatchTimer);
      }
    },
    saveTimer(form,batchTimer){
      if(parseFloat(this.matchBatchForm.beforediscount) == parseFloat(this.matchBatchForm.afterdiscount)){
        this.showMsg("调价前和调价后折扣相同,不需要调价,请核实","error")
        return;
      }
      //取运营商 业务类型 分销商 省份 中文名称
      form.busname = this.bus.find(item =>{ return item.busuuid == form.busuuid; }).busname;
      form.operator = this.operator.find(item =>{ return item.operatoruid == form.operatoruid; }).operatorname;
      form.province = this.info.find(item =>{ return item.provinceuuid == form.provinceuuid}).provincename;
      //计算分销商名称
      let name = "";
      form.useruuid.forEach(itemUser => {
        name += this.users.find(item => {return item.user.useruuid == itemUser }).user.username+",";
      });
      form.downName = name.substring(0,name.lastIndexOf(","));

      form.executeTime = (form.executeTime == "" || form.executeTime == undefined) ? "" : moment(form.executeTime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss')
      form.batchTimer = batchTimer;

      batchProductTimer(form).then(datas => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,"error")
        } else {
          this.showMsg("保存成功,可进入调价列表查看","success")
          this.matchFormBatchLoading = false;
        }
      });
    },
    handleEdit (row) {
      //处理地市
      this.findAllCity(row.provincialInformation.provincename);
      this.editFormVisible = true;
      this.downfindlist();
      let para = {
        downprouuid: row.downprouuid
      };
      findOpeProBusShop(para).then(datas => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,"error");
        } else if(data) {
          this.operator = data.operator;
          this.info = data.info;
          this.bus = data.bus;
          findOneProduct(para).then(datas => {
            let {message, code, data} = datas;
            if (code !== "0") {
              this.showMsg(message,"error");
            } else {
              this.editForm.operatoruid = data.operators.operatoruid;
              this.editForm.provinceuuid = data.provincialInformation.provinceuuid;
              this.editForm.busuuid = data.businessType.busuuid;
              this.editForm.useruuid = data.user.useruuid;
              this.editForm.fastchargetype = data.fastchargetype + "";
              this.editForm.productCode = data.productCode;
              this.editForm.downfacevalue = data.downfacevalue;
              this.editForm.discount = data.discount;
              this.editForm.remark = data.remark;
              this.editForm.productName = data.productName;
              this.editForm.downprouuid = data.downprouuid;
              this.editForm.price = data.price;
              this.editForm.discountAmount = data.discountAmount;
              this.editForm.validity = data.validity;
              this.editForm.cityName = data.cityName;
            }
          });
        }
      });
    },
    editSubmit () {
      this.$confirm('确认提交吗？', '提示', {roundButton:true}).then(() => {
        let para = Object.assign({}, this.editForm);
        updateProduct(para).then((datas) => {
          this.resultSuccess(datas)
          this.editFormVisible = false;
        });
      });
    },
    discountChangeEdit () {
      this.editForm.discountAmount = this.editForm.discount * this.editForm.price;
    },
    downfindlist(){
      downfindlist().then(datas =>{
        let { message, code, data } = datas;
        if (code !== "0") {
          this.showMsg(message,"error")
        } else {
          this.ups =   data;
        }
      });
    },
  },
  mounted() {
    this.findAllDownShopInfo();
    this.findAllChannel();
    this.findOpeProBusShop();
    this.findAllUpShopInfo();
  }
}
</script>
